package com.parking.status.sync.netty.server;

import com.parking.status.sync.netty.client.BodyFrameEncoder;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
@Qualifier("serverChannelInitializer")
public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    
//    @Autowired
//    @Qualifier("serverChannelInboundHandler")
//    private ChannelInboundHandlerAdapter serverChannelInboundHandler;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();

        pipeline.addLast("framerdecoder", new ServerFrameDecoder());
//        pipeline.addLast("prepender", new LengthFieldPrepender(4, false));

        //检查空闲断开连接
//        pipeline.addLast("idleStateCheck", new IdleStateHandler(0, 0, 600));
//        pipeline.addLast("idleCheckHandler", new IdleStateCheckHandler());

        pipeline.addLast("bodymessage", new BodyFrameDecoder());

        pipeline.addLast("content", new ContentDecoder());
    }
}